package com.wolfcode.record.controller;

import com.wolfcode.common.annotation.Log;
import com.wolfcode.common.core.controller.BaseController;
import com.wolfcode.common.core.domain.AjaxResult;
import com.wolfcode.common.core.page.TableDataInfo;
import com.wolfcode.common.enums.BusinessType;
import com.wolfcode.common.utils.poi.ExcelUtil;
import com.wolfcode.record.domain.BusCustomerInformation;
import com.wolfcode.record.service.IBusCustomerInformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户信息Controller
 * 
 * @author wolfcode
 * @date 2022-12-08
 */
@RestController
@RequestMapping("/record/information")
public class BusCustomerInformationController extends BaseController
{
    @Autowired
    private IBusCustomerInformationService busCustomerInformationService;

    /**
     * 查询客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('record:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusCustomerInformation busCustomerInformation)
    {
        startPage();
        List<BusCustomerInformation> list = busCustomerInformationService.selectBusCustomerInformationList(busCustomerInformation);
        return getDataTable(list);
    }

    /**
     * 导出客户信息列表
     */
    @PreAuthorize("@ss.hasPermi('record:information:export')")
    @Log(title = "客户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusCustomerInformation busCustomerInformation)
    {
        List<BusCustomerInformation> list = busCustomerInformationService.selectBusCustomerInformationList(busCustomerInformation);
        ExcelUtil<BusCustomerInformation> util = new ExcelUtil<BusCustomerInformation>(BusCustomerInformation.class);
        util.exportExcel(response, list, "客户信息数据");
    }

    /**
     * 获取客户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:information:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busCustomerInformationService.selectBusCustomerInformationById(id));
    }

    /**
     * 新增客户信息
     */
    @PreAuthorize("@ss.hasPermi('record:information:add')")
    @Log(title = "客户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusCustomerInformation busCustomerInformation)
    {
        return toAjax(busCustomerInformationService.insertBusCustomerInformation(busCustomerInformation));
    }

    /**
     * 修改客户信息
     */
    @PreAuthorize("@ss.hasPermi('record:information:edit')")
    @Log(title = "客户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusCustomerInformation busCustomerInformation)
    {
        return toAjax(busCustomerInformationService.updateBusCustomerInformation(busCustomerInformation));
    }

    /**
     * 删除客户信息
     */
    @PreAuthorize("@ss.hasPermi('record:information:remove')")
    @Log(title = "客户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busCustomerInformationService.deleteBusCustomerInformationByIds(ids));
    }
}
